home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / doc / other / maintain.doc < prev    next >
Encoding:
Text File  |  1992-11-19  |  49.0 KB  |  1,309 lines

  1.  
  2.  
  3.  
  4.      DATA BASE                    INGRES                        Page 1
  5.  
  6.  
  7.              CREATING AND MAINTAINING A DATABASE USING INGRES
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.                                     by
  24.                               Robert Epstein
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.                         Memorandum No. ERL - M77-71
  44.                              December 16, 1977
  45.  
  46.  
  47.  
  48.                       Electronics Research Laboratory
  49.                           College of Engineering
  50.                     University of California, Berkeley
  51.                                    94720
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.              CREATING AND MAINTAINING A DATABASE USING INGRES
  62.  
  63.  
  64.  
  65.      1.   INTRODUCTION
  66.  
  67.      In this paper we describe how to create, structure  and  maintain
  68.      relations  in  INGRES.  It is assumed that the reader is familiar
  69.      with INGRES and understands QUEL, the INGRES query language.   It
  70.      is  strongly  suggested  that the document "A Tutorial on INGRES"
  71.      (ERL M77/25) be read first.
  72.  
  73.      This paper is divided into six sections
  74.  
  75.           1.  Introduction
  76.  
  77.           2.  Creating a Relation
  78.  
  79.           3.  Using Copy
  80.  
  81.           4.  Storage Structures
  82.  
  83.           5.  Secondary Indices
  84.  
  85.           6.  Recovery and Data Update
  86.  
  87.      To create a new data base you must be a  valid  INGRES  user  and
  88.      have "create data base" permission.  These permissions are grant-
  89.      ed by the "ingres" superuser.  If you pass those two requirements
  90.      you can create a data base using the command to the Unix shell:
  91.  
  92.      % creatdb mydata
  93.  
  94.      where "mydata" is the name of the  data  base.   You  become  the
  95.      "data  base administrator" (DBA) for mydata.  As the DBA you have
  96.      certain special powers.
  97.  
  98.      1.  Any relation created by you can be accessed  by  anyone  else
  99.          using  "mydata".   If any other user creates a relation it is
  100.          strictly private and cannot be accessed by  the  DBA  or  any
  101.          other user.
  102.  
  103.      2.  You can use the "-u" flag in ingres and printr. This  enables
  104.          you  to use ingres on "mydata" with someone else's id.  Refer
  105.          to the INGRES reference manual  under  sections  ingres(unix)
  106.          and users(files) for details.
  107.  
  108.      3.  You can run sysmod, restore and purge on "mydata".
  109.  
  110.      4.  The data base by default is created  to  allow  for  multiple
  111.          concurrent  users.   If  only one user will ever use the data
  112.          base at a time, the data base administrator can turn off  the
  113.          concurrency  control.   Refer  to creatdb(unix) in the INGRES
  114.          reference manual.
  115.  
  116.      Once a data base has been created you should immediately run
  117.  
  118.      % sysmod mydata
  119.  
  120.      This program will convert the system relations  to  their  "best"
  121.      structure for use in INGRES.  Sysmod will be explained further in
  122.      section 4.
  123.  
  124.      As a DBA or as a user you can create and structure new  relations
  125.      in any data base to which you have access.  The remainder of this
  126.      paper describes how this is done.
  127.  
  128.  
  129.      2.   CREATING NEW RELATIONS IN INGRES
  130.  
  131.      There are two ways to create new relations in INGRES.
  132.  
  133.           create
  134.           retrieve into
  135.  
  136.      "Retrieve into" is used to form a new relation from one  or  more
  137.      existing  relations.   "Create"  is used to create a new relation
  138.      with no tuples in it.
  139.  
  140.      example 1:
  141.  
  142.           range of p is parts
  143.           range of s is supply
  144.           retrieve into newsupply(
  145.                         number = s.snum,
  146.                         p.pname,
  147.                         s.shipdate)
  148.           where s.pnum = p.pnum
  149.  
  150.      example 2:
  151.  
  152.           create newsupply(
  153.                  number = i2,
  154.                  pname = c20,
  155.                  shipdate = c8)
  156.  
  157.      In example 1 INGRES creates a new  relation  called  "newsupply",
  158.      computing what the format of each domain should be.  The query is
  159.      then run and newsupply is modified to "cheapsort".  (This will be
  160.      covered in more detail in section 4.)
  161.  
  162.      In example 2 "newsupply" is created and the name and  format  for
  163.      each domain is given.  The format types which are allowed are:
  164.  
  165.           i1             1  byte integer
  166.           i2             2   "      "
  167.           i4             4   "      "
  168.           f4             4  byte floating point number
  169.           f8             8   "      "       "     "
  170.           c1,c2,..,c255  1,2,..,255 byte character
  171.  
  172.      In example 2, the width of an individual tuple is 30 bytes  (2  +
  173.      20  + 8), and the relation has three domains.  Beware that INGRES
  174.      has limits.  A relation cannot have more than 49 domains and  the
  175.      tuple width cannot exceed 498 bytes.
  176.  
  177.      UNIX allocates space on a  disk  in  units  of  512  byte  pages.
  178.      INGRES gets a performance advantage by doing I/O in one block un-
  179.      its.  Therefore  relations  are  divided  into  512  byte  pages.
  180.      INGRES  never  splits a tuple between two pages.  Thus some space
  181.      can be wasted.  There is an overhead of 12 bytes per page plus  2
  182.      bytes for every tuple on the page.  The formulas are:
  183.  
  184.           number tuples per page = 500/(tuple width + 2)
  185.  
  186.           wasted space = 500 - number of tuples per page
  187.           *(tuple width +2)
  188.  
  189.      For our example there are
  190.  
  191.           22 = 500/(20 + 2)
  192.  
  193.           16 = 500 - 22 * (20 + 2)
  194.  
  195.      22 tuples per page and 16 bytes wasted per page.  These  computa-
  196.      tions  are valid only for uncompressed relations.  We will return
  197.      to this subject in section 4 when we discuss compression.
  198.  
  199.      If you forget a domain name or format, use  the  "help"  command.
  200.      For example if you gave the INGRES command:
  201.  
  202.           help newsupply
  203.  
  204.      the following would be printed:
  205.  
  206.      Relation:               newsupply
  207.      Owner:                  bob
  208.      Tuple width:            30
  209.      Saved until:            Thu Nov 10 16:17:06 1977
  210.      Number of tuples:       0
  211.      Storage structure:      paged heap
  212.      Relation type:          user relation
  213.  
  214.       attribute name    type  length  keyno.
  215.  
  216.       number             i       2
  217.       pname              c      20
  218.       shipdate           c       8
  219.  
  220.      Notice that every relation has an expiration date.  This  is  set
  221.      to  be  one  week  from the time when it was created.  The "save"
  222.      command  can  be  used  to  save  the   relation   longer.    See
  223.      "save(quel)" and "purge(unix)" in the INGRES reference manual.
  224.  
  225.      3.   COPYING DATA TO AND FROM INGRES
  226.  
  227.      Once a relation is created, there are two mechanisms for  insert-
  228.      ing new data:
  229.  
  230.           append command
  231.           copy command
  232.  
  233.      Append is used to insert tuples one at a time, or for filling one
  234.      relation from other relations.
  235.  
  236.      Copy is used for copying data from a UNIX file into  a  relation.
  237.      It  is used for copying data from another program, or for copying
  238.      data from another system. It is also the most convenient  way  to
  239.      copy any data larger than a few tuples.
  240.  
  241.      Let's begin by creating a simple relation and loading  data  into
  242.      it.
  243.  
  244.      Example:
  245.  
  246.           create donation (name = c10, amount = f4, ext = i2)
  247.  
  248.      Now suppose we have two people to enter. The  simplest  procedure
  249.      is  probably  to  run  the two queries in INGRES using the append
  250.      command.
  251.  
  252.           append to donation (name="frank",amount = 5,ext = 204)
  253.  
  254.           append to donation (name="harry",ext = 209,amount = 4.50)
  255.  
  256.      Note that the order in which  the  domains  are  given  does  not
  257.      matter.   INGRES  matches by recognizing attribute names and does
  258.      not care in what order attributes are listed.  Here is  what  the
  259.      relation "donation" looks like now:
  260.  
  261.      donation relation
  262.  
  263.      |name      |amount    |ext   |
  264.      |----------------------------|
  265.      |frank     |5.000     |204   |
  266.      |harry     |4.500     |209   |
  267.      |----------------------------|
  268.  
  269.      We now have two people entered into the donation relation.   Sup-
  270.      pose we had fifty more to enter.  Using the append command is far
  271.      too tedious since so much typing is involved for each tuple.  The
  272.      copy command will better suit our purposes.
  273.  
  274.      Copy can take data from a regular Unix file in a variety of  for-
  275.      mats  and append it to a relation.  To use the copy command first
  276.      create a Unix file (typically using "ed") containing the data.
  277.  
  278.      For example, let's put five new names in a file using the editor.
  279.  
  280.      % ed
  281.      a
  282.      bill,3.50,302
  283.      sam,10.00,410
  284.      susan,,100
  285.      sally,.5,305
  286.      george,4.00,302
  287.      .
  288.      w newdom
  289.      68
  290.      q
  291.      %
  292.  
  293.      The format of the above file is a name followed by a comma,  fol-
  294.      lowed by the amount, then a comma, then the extension, and final-
  295.      ly a newline.  Null entries, for example the  amount  for  susan,
  296.      are perfectly legal and default to zero for numerical domains and
  297.      blanks for character domains.
  298.  
  299.      To use copy we enter INGRES and give the copy command.
  300.  
  301.           copy donation (name = c0, amount = c0, ext = c0)
  302.                   from "/mnt/bob/newdom"
  303.  
  304.      Here is how the copy command works:
  305.  
  306.           copy relname (list of what to copy) from "full pathname"
  307.  
  308.      In the case above we wrote:
  309.  
  310.           copy donation (. . .) from "/mnt/bob/newdom"
  311.  
  312.      Although amount and ext are stored in the relation as f4  (float-
  313.      ing  point)  and i2 (integer), in the Unix file they were entered
  314.      as characters.  In specifying the format of the domain, copy  ac-
  315.      cepts:
  316.  
  317.           domain = format
  318.  
  319.      where domain is the domain name and the format in the  UNIX  file
  320.      is one of
  321.  
  322.           i1, i2, i4         (true binary integer of size 1, 2, or 4)
  323.           f4, f8             (true binary float point of size 4 or 8)
  324.           c1, c2, c3,...c255 (a fixed length character string)
  325.           c0                 (a variable length character string de-
  326.                              limited by a comma, tab or new line)
  327.  
  328.      In the example we use
  329.  
  330.           name = c0, amount = c0, extension = c0
  331.  
  332.      This means that each of the domains was stored in the  Unix  file
  333.      as  variable length character strings.  Copy takes the first com-
  334.      ma, tab, or new line character as the end of the string.  This by
  335.      far is the most common use of copy when the data is being entered
  336.      into a relation for the first time.
  337.  
  338.      Copy can also be used to copy data from a relation  into  a  Unix
  339.      file.  For example:
  340.  
  341.           copy donation (name = c10, amount = c10, ext = c5)
  342.                    into "/mnt/bob/data"
  343.  
  344.      This will cause the following to happen:
  345.  
  346.      1.  If the file /mnt/bob/data already  exists  it  will  be  des-
  347.          troyed.
  348.  
  349.      2.  The file is created in mode 600 (read/write by you only)
  350.  
  351.      3.  Name will be copied as a 10 character field, immediately fol-
  352.          lowed by amount, immediately followed by ext.  Amount will be
  353.          converted to a character field 10 characters wide.  Ext  will
  354.          be converted to a character field 5 characters wide.
  355.  
  356.      The file "/mnt/bob/data" would be a stream of characters  looking
  357.      like this:
  358.  
  359.      frank          5.000  204harry          4.500  209bill
  360.                 3.500  302sam           10.000  410susan
  361.             0.000  100sally          0.500  305george
  362.         4.000  302
  363.  
  364.  
  365.      The output was broken into four lines to  make  it  fit  on  this
  366.      page.  In actuality the file is a single line.  Another example:
  367.  
  368.           copy (name = c0, colon = d1, ext = c0, comma = d1
  369.                   amt = c0, nl = d1) into "/mnt/bob/data"
  370.  
  371.      In this example "c0" is interpreted to mean "use the  appropriate
  372.      character  format".  For character domains it is the width of the
  373.      domain.  Numeric domains are converted to characters according to
  374.      the INGRES defaults (see ingres(unix)).
  375.  
  376.      The statements:
  377.  
  378.           colon = d1
  379.           comma = d1
  380.           nl = d1
  381.  
  382.      are used to insert one colon, comma, and newline into  the  file.
  383.      The format "d1" is interpreted to mean one dummy character.  When
  384.      copying into a Unix file, a selected set of characters can be in-
  385.      serted  into the  file  using  this "dummy domain" specification.
  386.      Here is what the file "/mnt/bob/data" would look like:
  387.  
  388.      frank     :   204,     5.000
  389.      harry     :   209,     4.500
  390.      bill      :   302,     3.500
  391.      sam       :   410,    10.000
  392.      susan     :   100,     0.000
  393.      sally     :   305,     0.500
  394.      george    :   302,     4.000
  395.  
  396.  
  397.      If you wanted a file with the true binary representation  of  the
  398.      numbers you would use:
  399.  
  400.           copy (name = c10, amount = f4, ext = i2)
  401.  
  402.      This would create a file with the exact copy of each  tuple,  one
  403.      after  the  other.   This  is frequently desireable for temporary
  404.      backup purposes and it guarantees  that  floating  point  domains
  405.      will be exact.
  406.  
  407.  
  408.      TYPICAL ERRORS
  409.  
  410.      There are 17 different errors that can occur in copy.  We will go
  411.      through the most common ones.
  412.  
  413.      Suppose you have a file with
  414.  
  415.      bill,3.5,302
  416.      sam,10,410,
  417.      susan,3,100
  418.  
  419.      and run the copy command
  420.  
  421.           copy donation (name = c0, amount = c0, ext = c0)
  422.                   from "/mnt/bob/data"
  423.  
  424.      You would get the error message
  425.  
  426.      5809: COPY: bad input string for domain amount. Input was "susan".
  427.      There were 2 tuples sucessfully copied from /mnt/bob/data into
  428.      donation.
  429.  
  430.      What happened is that line 2 had an extra comma.  The  first  two
  431.      tuples  were  copied  correctly.   For  the next tuple, name = ""
  432.      (blank), amount = "susan", and ext = "3". Since "susan" is not  a
  433.      proper floating point number, an error was generated and process-
  434.      ing was stopped after two tuples.
  435.  
  436.      If you tried to copy the file with a file such as
  437.  
  438.      nancy,5.0,35000
  439.  
  440.      you would get the error message
  441.  
  442.      5809: COPY: bad input string for domain ext. Input was "35000".
  443.      There were 0 tuples successfully copied from /mnt/bob/data into
  444.      donation.
  445.  
  446.      Here, since ext is an i2 (integer) domain, it cannot  exceed  the
  447.      value 32767.
  448.  
  449.      There are numerous other error messages, most of which are  self-
  450.      explanatory.
  451.  
  452.      In addition there are three, non-fatal warnings which may  appear
  453.      on a copy "from".
  454.  
  455.      If you are copying from a file into a relation which is  ISAM  or
  456.      hash,  a count of the number of duplicate tuples will appear, (if
  457.      there were any).  This will never appear on a "heap"  because  no
  458.      duplicate checking is performed.
  459.  
  460.      INGRES does not allow control characters (such as "bell" etc.) to
  461.      be  stored.   If  copy  reads any control characters, it converts
  462.      them to blanks and reports the number of domains that had control
  463.      characters in them.
  464.  
  465.      If you are copying using the c0 option, copy will report  if  any
  466.      character  strings  were  longer than their domains and had to be
  467.      truncated.
  468.  
  469.  
  470.      SPECIAL FEATURES
  471.  
  472.         There are a few special functions  that  make  copy  a  little
  473.      easier to use
  474.  
  475.      1.  Bulk copy
  476.  
  477.      If you ask for:
  478.  
  479.          copy relname () from "file"
  480.              or
  481.          copy relname () into "file"
  482.  
  483.      copy expands the statement to mean:
  484.  
  485.           copy each domain in its proper order according to its proper
  486.           format.
  487.  
  488.      So, if you said
  489.  
  490.          copy donation () into "/mnt/bob/donation"
  491.  
  492.      it would be the same as asking for:
  493.  
  494.          copy donation (name = c10, amount = f4, ext = i2)
  495.              into "/mnt/bob/donation"
  496.  
  497.      This provides a convenient way to copy  whole  relations  to  and
  498.      from INGRES.
  499.  
  500.      2.  Dummy Domains
  501.  
  502.      If you are copying data from another computer  or  program,  fre-
  503.      quently there will be a portion of data that you will want to ig-
  504.      nore.  This can be done using the dummy domain specifications d0,
  505.      d1, d2 ... d511.  For example
  506.  
  507.          copy rel (dom1 = c5, dummy = d2, dom2 = i4,
  508.              dumb = d0) from "/mnt/me/data"
  509.  
  510.      The first five characters are put in dom1, the next  two  charac-
  511.      ters are ignored.  The next four bytes are an i4 (integer) and go
  512.      in dom2, and the remaining delimited string is ignored.  The name
  513.      given to a dummy specifier is ignored.
  514.  
  515.      As mentioned previously, dummy domains can  be  used  on  a  copy
  516.      "into" a Unix file for inserting special characters.  The list of
  517.      recognizable names includes:
  518.  
  519.           nl        newline
  520.           tab       tab character
  521.           sp        space
  522.           nul       a zero byte
  523.           null      a zero byte
  524.           comma     ,
  525.           dash      -
  526.           colon     :
  527.           lparen    (
  528.           rparen    )
  529.  
  530.      3.  Truncation
  531.  
  532.      It is not uncommon to have a mistake  occur  and  need  to  start
  533.      over.  The simplest way to do that is to "truncate" the relation.
  534.      This is done by the command:
  535.  
  536.          modify relname to truncated
  537.  
  538.      This has the effect of removing all tuples in relname,  releasing
  539.      all disk space, and making relname a heap again.  It is the logi-
  540.      cal equivalent of a destroy followed by a create (but with a  lot
  541.      less typing).
  542.  
  543.      Since formatting mistakes are possible with copy, it is not  gen-
  544.      erally  a good idea to copy data into a relation that already has
  545.      valid data in it.  The best procedure is to  create  a  temporary
  546.      relation  with  the  same domains as the existing relation.  Copy
  547.      data into the temporary relation and then append it to  the  real
  548.      relation.  For example:
  549.  
  550.              create tempdom(name=c10,amount=f4,ext=i2)
  551.  
  552.              copy tempdom(name=c0,amount=c0,ext=c0)
  553.              from "/mnt/bob/data"
  554.  
  555.              range of td is tempdom
  556.              append to donation(td.all)
  557.  
  558.      4.  Specifing Delimitors.
  559.  
  560.      Sometimes it is desirable to specify what the delimiting  charac-
  561.      ter  should  be  on  a  copy  "from" a file.  This can be done by
  562.      specifing:
  563.  
  564.              domain = c0delim
  565.  
  566.      where "delim" is a valid delimitor taken from the list of  recog-
  567.      nizable  names.   This  list  was summarized on the previous page
  568.      under "dummy domains".  For example:
  569.  
  570.              copy donation (name = c0nl) from "/mnt/me/data"
  571.  
  572.      will copy names from the file to the relation.  Only a  new  line
  573.      will delimit the names so any commas or tabs will be passed along
  574.      as part of the name.
  575.  
  576.      When copying "into" a Unix file, the "delim" is actually  written
  577.      into the file, so on a copy "into" the specification:
  578.  
  579.              copy donation (name = c0nl) into "/mnt/me/file"
  580.  
  581.      will cause "name" to be written followed by a new line character.
  582.  
  583.  
  584.      4.   CHOOSING THE BEST STORAGE STRUCTURES
  585.  
  586.  
  587.      We now turn to the issue of efficiency.  Once you have created  a
  588.      relation  and  inserted  your  data  using either copy or append,
  589.      INGRES can process any query on the relation.  There are  several
  590.      things  you  can do to improve the speed at which INGRES can pro-
  591.      cess a query.
  592.  
  593.      INGRES can store a relation in three  different  internal  struc-
  594.      tures.   These  are  called "heap", "isam", and "hash".  First we
  595.      will briefly describe each structure and then  later  expand  our
  596.      discussion.
  597.  
  598.      HEAP
  599.  
  600.      When a relation is first created, it  is  created  as  a  "heap".
  601.      There are two important properties about a heap: duplicate tuples
  602.      are not removed, and nothing is known about the location  of  the
  603.      tuples.  If you ran the query:
  604.  
  605.           range of d is donation
  606.           retrieve (d.amount) where d.name = "bill"
  607.  
  608.      INGRES would have to read every tuple in the relation looking for
  609.      those  with  name  "bill".  If the relation is small this isn't a
  610.      serious matter.  But if the relation is very large, this can take
  611.      minutes (or even hours!).
  612.  
  613.      HASH
  614.  
  615.      A relation whose structure is "hash"  can  give  fast  access  to
  616.      searches on certain domains.  (Those domains are usually referred
  617.      to as "keyed domains".) In addition, a "hashed" relation contains
  618.      no  duplicate tuples.  For example, suppose the donation relation
  619.      is stored hashed on domain "name". Then the query:
  620.  
  621.           retrieve (d.amount) where d.name = "bill"
  622.  
  623.      will run quickly since INGRES knows approximately where  on  disk
  624.      the  tuple is stored.  If the relation contains only a few tuples
  625.      you won't notice the difference between a  "heap"  and  a  "hash"
  626.      structure.  But as the relation becomes larger, the difference in
  627.      speed becomes much more noticeable.
  628.  
  629.      ISAM
  630.  
  631.      An isam structure is one where the relation is sorted on  one  or
  632.      more  domains,  (also called keyed domains).  Duplicates are also
  633.      removed on "isam relations".  When new tuples are  appended  they
  634.      are  placed "approximately" in their sorted position in the rela-
  635.      tion.  (The "approximately" will be explained a bit later.)
  636.  
  637.      Suppose donation is isam on name.  To process the query
  638.  
  639.           retrieve (d.amount) where d.name = "bill"
  640.  
  641.      INGRES will determine where in the sorted order the  name  "bill"
  642.      would be and read only those portions of the relation.
  643.  
  644.      Since the relation is approximately sorted, an isam structure  is
  645.      also efficient for processing the query:
  646.  
  647.           retrieve (d.amount) where d.name >= "b" and d.name < "g"
  648.  
  649.      This query would retrieve all names beginning  with  "b"  through
  650.      "f".   The entire relation would not have to be searched since it
  651.      is isam on name.
  652.  
  653.  
  654.      SPECIFYING THE STORAGE STRUCTURE
  655.  
  656.      Any user created relation can be converted to any storage  struc-
  657.      ture using the "modify" command.  For example
  658.  
  659.           modify donation to hash on name
  660.      or
  661.           modify donation to isam on name
  662.  
  663.      or even
  664.  
  665.           modify donation to heap
  666.  
  667.  
  668.      PRIMARY AND OVERFLOW PAGES
  669.  
  670.      At this point it is necessary to introduce the concepts  of  pri-
  671.      mary  and  overflow pages on hash and isam structures.  Both hash
  672.      and isam are techniques for assigning specific tuples to specific
  673.      pages  of  a  relation  based on the tuple's keyed domains.  Thus
  674.      each page will contain only a certain specified subset of the re-
  675.      lation.
  676.  
  677.      When a new tuple is appended to a hash or isam  relation,  INGRES
  678.      first determines what page it belongs to, and then looks for room
  679.      on that page.  If there is space then the tuple is placed on that
  680.      page.   If  not, then an "overflow" page is created and the tuple
  681.      is placed there.
  682.  
  683.      The overflow page is linked to the original page.   The  original
  684.      page  is  called the "primary" page.  If the overflow page became
  685.      full, then INGRES would connect an overflow page to it.  We would
  686.      then  have one primary page linked to an overflow page, linked to
  687.      another overflow page.  Overflow pages are dynamically  added  as
  688.      needed.
  689.  
  690.  
  691.      SPECIFYING FREE SPACE
  692.  
  693.      The modify command also lets you specify how much room  to  leave
  694.      for the relation to grow.  As was mentiond in "create", relations
  695.      are divided into pages.  A "fillfactor" can be  used  to  specify
  696.      how  full  to  make  each  primary page.  This decision should be
  697.      based only on whether more tuples will be appended to  the  rela-
  698.      tion.  For example:
  699.  
  700.           modify donation to isam on name where fillfactor = 100
  701.  
  702.      This tells modify to make each page 100% full if at all possible.
  703.  
  704.           modify donation to isam on name where fillfactor = 25
  705.  
  706.      This will leave each page 25% full or, in other words, 75% empty.
  707.      We would do this if we had roughly 1/4 of the data already loaded
  708.      and it was fairly well distributed about the alphabet.
  709.  
  710.      Keep in mind that if you don't  specify  the  fillfactor,  INGRES
  711.      will  typically default to a reasonable choice.  Also when a page
  712.      becomes full, INGRES automatically creates an "overflow" page  so
  713.      it is never the case that a relation will be unable to expand.
  714.  
  715.      When modifying a relation to hash, an additional parameter  "min-
  716.      pages"  can  be  specified.   Modify will guarantee that at least
  717.      "minpage" primary pages will be allocated for the relation.
  718.  
  719.      Modify computes how may primary pages will be needed to store the
  720.      existing  tuples  at  the  specified  fillfactor assuming that no
  721.      overflow pages will be necessary originally.  If that  number  is
  722.      less than minpages, then minpages is used instead.
  723.  
  724.      For example:
  725.  
  726.           modify donation to hash on name where fillfactor = 50,
  727.                minpages = 1
  728.  
  729.           modify donation to hash on name where minpages = 150
  730.  
  731.      In the first case we guarantee that no more pages than are neces-
  732.      sary will be used for 50% occupancy.  The second case is typical-
  733.      ly used for modifying an empty or near empty  relation.   If  the
  734.      approximate  maximum  size  of  the relation is known in advance,
  735.      minpages can be used to guarantee that the relation will have its
  736.      expected maximum size.
  737.  
  738.      There is one other option available for hash  called  "maxpages".
  739.      Its  syntax  is  the same as minpages.  It can be used to specify
  740.      the maximum number of primary pages to use.
  741.  
  742.      COMPRESSION
  743.  
  744.      The three storage structures (heap, hash,  isam)  can  optionally
  745.      have  "compression"  applied  to  them.  To do this, refer to the
  746.      storage structures  as  cheap,  chash,  and  cisam.   Compression
  747.      reduces  the amount of space needed to store each tuple internal-
  748.      ly.  The current compression technique is  to  suppress  trailing
  749.      blanks  in  character  domains.  Using compression will never re-
  750.      quire more space and typically it can save disk space and improve
  751.      performance.  Here is an example:
  752.  
  753.           modify donation to cisam on name where fillfactor = 100
  754.  
  755.      This will make donation a  compressed  isam  structure  and  fill
  756.      every page as full as possible.  With compression, each tuple can
  757.      have a different compressed length.  Thus the  number  of  tuples
  758.      that can fit on one page will depend on how successfully they can
  759.      be compressed.
  760.  
  761.      Compressed relations can be more expensive to update.  In partic-
  762.      ular  if  a  replace  is  done  on  one  or  more domains and the
  763.      compressed tuple is no longer the same length, then  INGRES  must
  764.      look for a new place to put the tuple.
  765.  
  766.  
  767.      TWO VARIATIONS ON A THEME
  768.  
  769.      As mentioned, duplicates are not removed from a  relation  stored
  770.      as  a  heap.  Frequently it is desirable to remove duplicates and
  771.      sort a heap relation.  One way of doing this is to modify the re-
  772.      lation  to  isam  specifying the order in which to sort the rela-
  773.      tion.  An alternative to this is  to  use  either  "heapsort"  or
  774.      "cheapsort".  For example
  775.  
  776.           modify donation to heapsort on name, ext
  777.  
  778.      This will sort the relation by name then  ext.   The  tuples  are
  779.      further  sorted  on the remaining domains, in the order they were
  780.      listed in the original create statement.  So in this case the re-
  781.      lation  will  be sorted on name then ext and then amount.  Dupli-
  782.      cate tuples are always removed.  The relation will be left  as  a
  783.      heap.   Heapsort  and  cheapsort  are intended for sorting a tem-
  784.      porary relation before printing and destroying it.   It  is  more
  785.      efficient than modifying to isam because with isam INGRES creates
  786.      a "directory" containing key information about  each  page.   The
  787.      relation will NOT be kept sorted when further updates occur.
  788.  
  789.      Examples:
  790.  
  791.      Here are a collection of examples and comments as  to  the  effi-
  792.      ciency  of  each  query.  The queries are based on the relations:
  793.      parts(pnum, pname, color, weight, qoh)
  794.      supply(snum, pnum, jnum, shipdate, quan)
  795.  
  796.      range of p is parts
  797.      range of s is supply
  798.  
  799.      modify parts to hash on pnum
  800.      modify supply to hash on snum,jnum
  801.  
  802.           retrieve (p.all) where p.pnum = 10
  803.  
  804.      INGRES will recognize that parts is hashed on pnum and go direct-
  805.      ly to the page where parts with number 10 would be stored.
  806.  
  807.           retrieve (p.all) where p.pname = "tape drive"
  808.  
  809.      INGRES will read the entire relation looking for matching pnames.
  810.  
  811.           retrieve (p.all) where p.pnum < 10  and p.pnum > 5
  812.  
  813.      INGRES will read the entire relation because no exact  value  for
  814.      pnum was given.
  815.  
  816.           retrieve (s.shipdate) where s.snum = 471 and s.jnum = 1008
  817.  
  818.      INGRES will recognize that supply is hashed on the combination of
  819.      snum and jnum and will go directly to the correct page.
  820.  
  821.           retrieve (s.shipdate) where s.snum = 471
  822.  
  823.      INGRES will read the entire relation.  Supply is  hashed  on  the
  824.      combination  of  snum  and jnum.  Unless INGRES is given a unique
  825.      value for both, it cannot take advantage of  the  storage  struc-
  826.      ture.
  827.  
  828.           retrieve (p.pname, s.shipdate) where
  829.           p.pnum = s.pnum and s.snum = 471 and s.jnum = 1008
  830.  
  831.      INGRES will take advantage of both storage structures.   It  will
  832.      first  find  all  s.pnum  and  s.shipdate  where s.snum = 471 and
  833.      s.jnum = 1008.  After that it will look  for  all  p.pname  where
  834.      p.pnum is equal to the correct value.
  835.  
  836.      This example illustrates the idea that it is  frequently  a  good
  837.      idea  to hash a relation on the domains where it is "joined" with
  838.      another relation.  For example, in this case it is very common to
  839.      ask for p.pnum = s.pnum
  840.  
  841.      To summarize:
  842.  
  843.      To take advantage of a hash  structure,  INGRES  needs  an  exact
  844.      value for each key domain.  An exact value is anything such as:
  845.  
  846.           s.snum = 471
  847.           s.pnum = p.pnum
  848.  
  849.      An exact value is not
  850.  
  851.           s.snum >= 471
  852.           (s.snum = 10 or s.snum = 20)
  853.  
  854.      Now let's consider some cases using isam
  855.  
  856.           modify supply to isam on snum,shipdate
  857.           retrieve (s.all) where s.snum = 471
  858.           and s.shipdate > "75-12-31"
  859.           and s.shipdate < "77-01-01"
  860.  
  861.      Since supply is sorted first on snum and then on shipdate, INGRES
  862.      can  take full advantage of the isam structure to locate the por-
  863.      tions of supply which satisfy the query.
  864.  
  865.           retrieve (s.all) where s.snum = 47l
  866.  
  867.      Unlike hash, an isam structure can still  be  used  if  only  the
  868.      first key is provided.
  869.  
  870.           retrieve (s.all) where s.snum > 400 and s.snum < 500
  871.  
  872.      Again INGRES will take advantage of the structure.
  873.  
  874.           retrieve (s.all) where s.shipdate >= "75-12-31" and
  875.           s.shipdate <= "77-01-01"
  876.  
  877.      Here INGRES will read the entire relation.  This is  because  the
  878.      first key (snum) is not provided in the query.
  879.  
  880.      To summarize:
  881.  
  882.      Isam can provide improved access on either exact values or ranges
  883.      of  values.   It  is  useful as long as at least the first key is
  884.      provided.
  885.  
  886.      To locate where the  tuples  are  in  an  isam  relation,  INGRES
  887.      searches  the  isam directory for that relation.  When a relation
  888.      is modified to isam, the tuples are first sorted  and  duplicates
  889.      are  removed.   Next,  the  relation  is filled (according to the
  890.      fillfactor) starting at page 0, 1, 2... for as many pages as  are
  891.      needed.
  892.  
  893.      Now the directory is built.  The key domains from the first tuple
  894.      on each page are collected and organized into a directory (stored
  895.      in the relation on disk).  The directory is never  changed  until
  896.      the next time a modify is done.
  897.  
  898.      Whenever a tuple is added  to  the  relation,  the  directory  is
  899.      searched  to  find  which  page the new tuple belongs on.  Within
  900.      that page, the individual tuples are NOT kept  sorted.   This  is
  901.      what is meant by "approximately" sorted.
  902.  
  903.  
  904.      HEAP v. HASH v. ISAM
  905.  
  906.      Let's now compare the relative advantages  and  disadvantages  of
  907.      each  option.  A relation is always created as a heap.  A heap is
  908.      the most efficient structure to use to initially fill a  relation
  909.      using copy or append.
  910.  
  911.      Space from deleted tuples of a heap is only reused  on  the  last
  912.      page.  No duplicate checking is done on a heap relation.
  913.  
  914.      Hash is advantageous for locating tuples referenced in a qualifi-
  915.      cation  by  an  exact  value.  The primary page for tuples with a
  916.      specific value can be easily computed.
  917.  
  918.      Isam is useful for both exact values and ranges of values.  Since
  919.      the isam directory must be searched to locate tuples, it is never
  920.      as efficient as hash.
  921.  
  922.  
  923.      OVERFLOW PAGES
  924.  
  925.      When a tuple is to be inserted and there is no more room  on  the
  926.      primary page of a relation, then an overflow page is created.  As
  927.      more tuples are inserted, additional overflow pages are added  as
  928.      needed.   Overflow  pages,  while  necessary, decrease the system
  929.      performance for retrieves and updates.
  930.  
  931.      For example, let's suppose that supply is hashed on snum and  has
  932.      10  primary  pages.   Suppose the value snum = 3 falls on page 7.
  933.      To find all snum = 3 requires INGRES to search primary page 7 and
  934.      all  overflow  pages  of page 7 (if any).  As more overflow pages
  935.      are added the time needed to search for snum = 3  will  increase.
  936.      Since  duplicates  are removed on isam and hash, this search must
  937.      be performed on appends and replaces also.
  938.  
  939.      When a hash or isam relation  has  too  many  overflow  pages  it
  940.      should  be  remodified to hash or isam again.  This will clear up
  941.      the relation and eliminate as many overflow pages as possible.
  942.  
  943.  
  944.      UNIQUE KEYS
  945.  
  946.      When choosing key domains for a relation it is desirable to  have
  947.      each  set of key domains as unique as possible.  For example, em-
  948.      ployee id numbers typically have no duplicate values, while some-
  949.      thing  like  color  is likely to have only a few distinct values,
  950.      and something like sex, to the best of our  knowledge,  has  only
  951.      two values.
  952.  
  953.      If a relation is hashed on domain sex then you can expect to have
  954.      all  males  on  one primary page and all its overflow pages and a
  955.      corresponding situation with females.  With a hash relation there
  956.      is no solution to this problem.  A trade-off must be made between
  957.      the most desirable key domains to use in a  qualification  versus
  958.      the uniqueness of the key values.
  959.  
  960.      Since isam structure can be used if at least  the  first  key  is
  961.      provided,  extra  key  domains can sometimes be added to increase
  962.      uniqueness.  For example, suppose the supply relation has only 10
  963.      unique  supplier  numbers  but  thousands of tuples.  Choosing an
  964.      isam structure with the keys snum and  jnum  will  probably  give
  965.      many  more  unique  keys.   However,  the  directory size will be
  966.      larger and consequently it will take longer to search.  When pro-
  967.      viding  additional  keys  just for the sake of increasing unique-
  968.      ness, try to use the smallest possible domains.
  969.  
  970.  
  971.      SYSTEM RELATIONS
  972.  
  973.      INGRES  uses  three  relations  ("relation",   "attribute",   and
  974.      "indexes")  to maintain and organize a data base.  The "relation"
  975.      relation has one tuple for each relation in the data  base.   The
  976.      "attribute" relation has one tuple for each attribute in each re-
  977.      lation.  The "indexes" relation has one tuple for each  secondary
  978.      index.
  979.  
  980.      INGRES accesses these relations in a very well defined manner.  A
  981.      program  called "sysmod" should be used to modify these relations
  982.      to hash on the appropriate domains.  To use sysmod the data  base
  983.      administrator types
  984.  
  985.      % sysmod data-base-name
  986.  
  987.      Sysmod should be run initially after the data base is created and
  988.      subsequently  as  relations  are created and the data base grows.
  989.      It is insufficient to run sysmod only once and forget  about  it.
  990.      Rerunning  sysmod  will  cause the system relations to be remodi-
  991.      fied.  This will typically remove most overflow pages and improve
  992.      system response time for everything.
  993.  
  994.      5.  SECONDARY INDICES
  995.  
  996.      Using an isam or hash structure provides a fast way to  find  tu-
  997.      ples  in  a relation given values for the key domains.  Sometimes
  998.      this is not enough.  For example, suppose we  have  the  donation
  999.      relation
  1000.  
  1001.           donation(name, amount, ext)
  1002.  
  1003.      hashed on name.  This will provide fast access to  queries  where
  1004.      the  qualification  has an exact value for name.  What if we also
  1005.      will be doing queries giving exact values for ext?
  1006.  
  1007.      Donation can be hashed either on name or ext, so we would have to
  1008.      choose  which  is  more  common and hash donation on that domain.
  1009.      The other domain (say ext) can have a secondary index.  A  secon-
  1010.      dary  index is a relation which contains each "ext" together with
  1011.      the exact location of where the tuple is in  the  relation  dona-
  1012.      tion.
  1013.  
  1014.      The command to create a secondary index is:
  1015.  
  1016.           index on donation is donext (ext)
  1017.  
  1018.      The general format is:
  1019.  
  1020.           index on relation_name is secondary_index_name (domains)
  1021.  
  1022.      Here we are asking INGRES to create a secondary index on the  re-
  1023.      lation donation.  The domain being indexed is "ext".  Indices are
  1024.      formed in three steps:
  1025.  
  1026.      1.  "Donext" is created as a heap.
  1027.      2.  For each tuple in donation, a tuple is inserted  in  "donext"
  1028.          with  the  value  for  ext  and  the  exact  location  of the
  1029.          corresponding tuple in donation.
  1030.      3.  By default "donext" is modified to isam.
  1031.  
  1032.      Now if you run the query
  1033.  
  1034.           range of d is donation
  1035.           retrieve(d.amount) where d.ext = 207
  1036.  
  1037.      INGRES will automatically look first in "donext" to  find  ext  =
  1038.      207.  When it finds one it then goes directly to the tuple in the
  1039.      donation relation.  Since "donext" is isam on ext, search for ext
  1040.      = 207 can typically be done rapidly.
  1041.  
  1042.      If you run the query
  1043.  
  1044.           retrieve(d.amount) where d.name = "frank"
  1045.  
  1046.      then INGRES will continue to use the hash structure of the  rela-
  1047.      tion "donation" to locate the qualifying tuples.
  1048.  
  1049.      Since secondary indices are themselves relations, they  also  can
  1050.      be  either hash, isam, chash or cisam.  It never makes sense to a
  1051.      secondary index a heap.
  1052.  
  1053.      The decision as to what structure to make them  on  involves  the
  1054.      same issues as were discussed before:
  1055.  
  1056.      Will the domains be referenced by exact value?
  1057.      Will they be referenced by ranges of value?
  1058.      etc.
  1059.  
  1060.      In this case the "ext" domain will be referenced by exact values,
  1061.      and since the relation is nearly full we will do:
  1062.  
  1063.           modify donext to hash on ext where fillfactor = 100
  1064.           and minpages = 1
  1065.  
  1066.      Secondary indices provide a way for INGRES to access tuples based
  1067.      on  domains  that  are  not key domains.  A relation can have any
  1068.      number of secondary indices and in addition each secondary  index
  1069.      can be an index on up to six domains of the primary relation.
  1070.  
  1071.      Whenever a tuple is replaced, deleted or appended  to  a  primary
  1072.      relation, all secondary indices must also be updated. Thus secon-
  1073.      dary indices are "not free". They increase the cost  of  updating
  1074.      the primary relation, but can decrease the cost of finding tuples
  1075.      in the primary relation.
  1076.  
  1077.      Whether a secondary index will improve performance or not strong-
  1078.      ly  depends  on the uniqueness of the values of the domains being
  1079.      indexed.  The primary concern is whether  searching  through  the
  1080.      secondary  index is more efficient than simply reading the entire
  1081.      primary relation.  In general it is if the number of tuples which
  1082.      satisfy  the qualification is less than the number of total pages
  1083.      (both primary and overflow) in the primary relation.
  1084.  
  1085.      For example if we frequently want to find all people who  donated
  1086.      less than five dollars, consider creating
  1087.  
  1088.           index on donation is donamount (amount)
  1089.  
  1090.      By default donamount will be isam on amount.  IF INGRES processes
  1091.      the query:
  1092.  
  1093.           retrieve(d.name) where d.amount < 5.0
  1094.  
  1095.      it will locate d.amount < 5.0 in the secondary index and for each
  1096.      tuple  it  finds  will fetch the corresponding tuple in donation.
  1097.      The tuples in donamount are sorted by amount but  the  tuples  in
  1098.      donation are not.  Thus in general each tuple fetch from donation
  1099.      via donamount will be on a different page.  Retrieval  using  the
  1100.      secondary  index can then cause more page reads than simply read-
  1101.      ing all of donation sequentially!  So in this example it would be
  1102.      a bad idea to create the secondary index.
  1103.  
  1104.      6.  RECOVERY AND DATA UPDATE
  1105.  
  1106.      INGRES has been carefully designed to protect the integrity of  a
  1107.      data base against certain classes of system failures.  To do this
  1108.      INGRES processes changes to a relation using what  we  call  "de-
  1109.      ferred update" or "batch file update".  In addition there are two
  1110.      INGRES programs "restore" and "purge" that can be used  to  check
  1111.      out  a  data  base after a system failure.  We will first discuss
  1112.      how deferred updates are created and  processed,  and  second  we
  1113.      will discuss the use of purge and restore.
  1114.  
  1115.      DEFERRED UPDATE (Batch update)
  1116.  
  1117.      An append, replace or delete command is run in four steps:
  1118.  
  1119.      1.  An empty batch file is created.
  1120.      2.  The command is run to  completion  and  each  change  to  the
  1121.          result relation is written into the batch file.
  1122.      3.  The batch file is read and the relation and its secondary in-
  1123.          dices (if any) are actually updated.
  1124.      4.  The batch file is destroyed and INGRES returns  back  to  the
  1125.          user.
  1126.  
  1127.      Deferred update defers all actual updating until the very end  of
  1128.      the query.  There are three advantages to doing this.
  1129.  
  1130.      l.  Provides recovery from system failures
  1131.  
  1132.      If the system "crashes" during an  update,  the  INGRES  recovery
  1133.      program  will  decide  to  either run the update to completion or
  1134.      else "back out" the update, leaving the relation as it looked be-
  1135.      fore the update was started.
  1136.  
  1137.      2.  Prevents infinite queries
  1138.  
  1139.      If "donation" were a heap and the query
  1140.  
  1141.          range of d is donation
  1142.          append to donation(d.all)
  1143.  
  1144.      were run without deferred update, it would terminate only when it
  1145.      ran  out  of  space  on disk!  This is because INGRES would start
  1146.      reading the relation from the beginning and appending each  tuple
  1147.      at  the  end.  It would soon start reading the tuples it had just
  1148.      previously appended  and  continue  indefinitely  to  "chase  its
  1149.      tail".
  1150.  
  1151.      While this query is certainly not  typical,  it  illustrates  the
  1152.      point.  There are certain classes of queries where problems occur
  1153.      if WHEN an update actually occurs is not precisely defined.  With
  1154.      deferred update we can guarantee consistent and logical results.
  1155.  
  1156.      3.  Speeds up processing of secondary indices
  1157.  
  1158.      Secondary indices can be updated faster if they are done one at a
  1159.      time  instead of all at once.  It also insures protection against
  1160.      the secondary index becoming inconsistent with its primary  rela-
  1161.      tion.
  1162.  
  1163.      TURNING DEFERRED UPDATE OFF
  1164.  
  1165.      If you are not persuaded by any of these arguments, INGRES allows
  1166.      you  to turn deferred update off!  Indeed there are certain cases
  1167.      when it is appropriate (although certainly not essential) to per-
  1168.      form updates directly, that is, the relation is updated while the
  1169.      query is being processed.
  1170.  
  1171.      To use direct update, you must be given permission by the  INGRES
  1172.      super  user.   Then  when  invoking  INGRES specify the "-b" flag
  1173.      which turns off batch update.
  1174.  
  1175.          % ingres mydate -b
  1176.  
  1177.      INGRES will use direct update on any relation  without  secondary
  1178.      indices. It will still silently use deferred update if a relation
  1179.      has any secondary indices.  By using the "-b" flag you  are  sac-
  1180.      rificing  points 1 and 2 above.  In most cases you SHOULD NOT use
  1181.      the -b flag.
  1182.  
  1183.      If you are using INGRES to interactively enter or change one  tu-
  1184.      ple at a time, it is slightly more efficient to have deferred up-
  1185.      date turned off.  If the system crashes during an update the per-
  1186.      son  entering  the  data  will  be aware of the situation and can
  1187.      check whether the tuple was updated or not.
  1188.  
  1189.      RESTORE
  1190.  
  1191.      INGRES is designed to recover from the  common  types  of  system
  1192.      crashes  which leave the Unix file system intact.  It can recover
  1193.      from updates, creates, destroys, modifies and index commands.
  1194.  
  1195.      INGRES is designed to "fail safe".  If  any  inconsistancies  are
  1196.      discovered  or  any  failures are returned from Unix, INGRES will
  1197.      generate a system error message (SYSERR) and exit.
  1198.  
  1199.      Whenever Unix crashes while INGRES  is  running  or  whenever  an
  1200.      INGRES  syserr  occurs,  it  is generally a good idea to have the
  1201.      date base administrator run the command
  1202.  
  1203.           % restore data_base_name
  1204.  
  1205.      The restore program performs the following functions:
  1206.  
  1207.      1.  Looks for batch update files.  If any are found, it  examines
  1208.          each  one  to see if it is complete.  If the system crash oc-
  1209.          cured while the batch file was being read and the  data  base
  1210.          being updated, then restore will complete the update.  Other-
  1211.          wise the batch file was not completed and it is  simply  des-
  1212.          troyed; the effect is as though the query had never been run.
  1213.  
  1214.      2.  Checks for uncompleted modify commands.  This  step  is  cru-
  1215.          cial.   It  guarantees that you will either have the relation
  1216.          as it existed before the modify, or restore will complete the
  1217.          modify  command.   Modify works by creating a new copy of the
  1218.          relation in the new structure.  Then when it is ready to  re-
  1219.          place  the  old  relation, it stores the new information in a
  1220.          "modify batch file". This enables restore  to  determine  the
  1221.          state of uncompleted modifies.
  1222.  
  1223.      3.  Checks consistency of system relations.  This check  is  used
  1224.          to  complete  "destory" commands, back out "create" commands,
  1225.          and back out or complete "index" commands  that  were  inter-
  1226.          rupted by a system crash.
  1227.  
  1228.      4.  Purges temporary relations and files.  Restore  executes  the
  1229.          "purge"  program  to remove temporary relations and temporary
  1230.          files created by the system.  Purge will be discussed in more
  1231.          detail a bit later.
  1232.  
  1233.      Restore cannot tell the user which queries  have  run  and  which
  1234.      have  not.   It can only identify those queries which were in the
  1235.      process of being run  when  the  crash  occured.   When  batching
  1236.      queries together, it is a good idea to save the output in a file.
  1237.      By having the monitor print out each query or set of queries, the
  1238.      user can later identify which queries were run.
  1239.  
  1240.      Restore has several options to increase its usability.  They  are
  1241.      specified by "flags".  The options include:
  1242.  
  1243.          -a            ask before doing anything
  1244.          -f            passed to purge. used to remove temporary files.
  1245.          -p            passed to purge.  used to destory expired rela-
  1246.                        tions.
  1247.          no database   restores all data bases for which you are the
  1248.                        dba.
  1249.  
  1250.      Of these options the "-a" is the most important.  It  can  happen
  1251.      that a Unix crash can cause a page of the system catalogues to be
  1252.      incorrect.  This might cause restore to destory a  relation.   In
  1253.      fact,  you  might want to "patch" the system relations to correct
  1254.      the problem.  No restore program can account for  all  possibili-
  1255.      ties.  It is therefore no replacement (fortunately) for a human.
  1256.  
  1257.      If "-a" is specified, restore will state what it wants to do  and
  1258.      then ask for permission.  It reads standard input and accepts "y"
  1259.      to mean go ahead and anything else to mean no.  For  example,  to
  1260.      have restore ask you before doing anything
  1261.  
  1262.           restore -a mydatabase
  1263.  
  1264.      To have it take "no" for all its questions
  1265.  
  1266.           restore -a mydatabase </dev/null
  1267.  
  1268.      Using the -a flag, restore might ask for  permission  to  perform
  1269.      some  cleanup;  for  example,  if it finds an attribute for which
  1270.      there is no corresponding relation, or if it  finds  a  secondary
  1271.      index for which there is no primary relation, etc.
  1272.  
  1273.      To date, we have never had a system crash which INGRES could  not
  1274.      recover  from.  This does not mean that it will never happen, but
  1275.      rather that it shouldn't be too great  a  concern  for  you.   It
  1276.      should  be mentioned that restore is not a substitution for doing
  1277.      periodic backing up, nor does it ever perform such a function.
  1278.  
  1279.      PURGE
  1280.  
  1281.      Purge can be used to report expired relations, destroy  temporary
  1282.      system  relations,  remove  extraneous files, and destory expired
  1283.      relations.  To use purge you must be the DBA for the data base.
  1284.  
  1285.           % purge mydatabase
  1286.  
  1287.      Purge has several options which are specified by flags which  are
  1288.      worth noting:
  1289.  
  1290.      -f   (default is off) remove all extraneous files.
  1291.           Each file is reported and then removed.  If "-f"
  1292.           is not specified then the file is only reported.
  1293.  
  1294.      -p   (default is off) destroy all expired relations.
  1295.           Each expired relation is reported and if "-p"
  1296.           was specified the relation is destroyed.
  1297.  
  1298.      Purge always destroys relations and files which are known  to  be
  1299.      INGRES   system   temporaries.   When  processing  multi-variable
  1300.      queries and queries with aggregate functions, INGRES will usually
  1301.      create  temporary relations with intermediate results.  These re-
  1302.      lations always begin with the  characters  "_SYS".  Other  INGRES
  1303.      commands  create  temporary  files  which also begin with "_SYS".
  1304.      Under normal processing they are always destroyed.  If  a  system
  1305.      crash occurs, they might be left.  Purge will always clean up the
  1306.      temporary system files.  It cleans up  the  user  relations  only
  1307.      when specifically asked to.
  1308.  
  1309.